package payrechargelogic

import (
	"context"

	model "gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/dao/model/recharge"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/pkg/xerrors"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/rpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type RechargeChannelListByCodeLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewRechargeChannelListByCodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RechargeChannelListByCodeLogic {
	return &RechargeChannelListByCodeLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *RechargeChannelListByCodeLogic) RechargeChannelListByCode(in *rpc.RechargeChannelByCodeRequest) (*rpc.RechargeChannelByCodeResponse, error) {
	var commonResp rpc.CommonResp

	ch, err := model.NewRechargeChannelModel(l.ctx, l.svcCtx.Db).GetRechargeChannelByCode(in.Code)
	if err != nil {
		commonResp.Code = xerrors.DBError
		commonResp.Message = "Database operation error"
		return nil, err
	}

	return &rpc.RechargeChannelByCodeResponse{
		Id:           ch.ID,
		MappingCode:  ch.MappingCode,
		Type:         ch.Type,
		Name:         ch.Name,
		Level:        ch.Level,
		UserGroup:    ch.UserGroup,
		BonusRate:    ch.BonusRate,
		MinAmount:    ch.MinAmount,
		MaxAmount:    ch.MaxAmount,
		AmountConfig: ch.AmountConfig,
		MerchantId:   ch.MerchantID,
		AppId:        ch.AppId,
		AppCode:      ch.AppCode,
		SecretKey:    ch.SecretKey,
		Url:          ch.URL,
		ReturnUrl:    ch.ReturnUrl,
		NotifyUrl:    ch.NotifyUrl,
		PubKey:       ch.PubKey,
		PrivateKey:   ch.PrivateKey,
		StartTime:    ch.StartTime,
		EndTime:      ch.EndTime,
		Sort:         ch.Sort,
		Status:       ch.Status,
		IsTestable:   ch.IsTestable,
		WhiteList:    ch.WhiteList,
		Remark:       ch.Remark,
		Icon:         ch.Icon,
		ChannelName:  ch.ChannelName,
		Inr:          ch.Coin,
	}, nil
}
